< previous page page_403 next page >

Page 403
Because all of these actions on the MDI parent file menu are also on the child form's file menu, you make this event public (see Listing 17.7).
Listing 17.7 MDIPARENT2.TXTHandling Menu Click Events
'*********************************************************************
' File menu handler for the MDI form when no windows are displayed.
' In this demo the child windows will have a menu just like this,
' so we will make this Public so the children can call this event.
'*********************************************************************
Public Sub mnuFileItems_Click(Index As Integer)
    Select Case Index
        '*************************************************************
        ' File New - Create a new child form, then display it.
        '*************************************************************
        Case 1
            Dim frmNew As New frmChild
            frmNew.Visible = True
        '*************************************************************
        ' File Open - Prompt the user for a filename, then load
        '   it into the child window (in OpenFile) if the user didn't
        '   press cancel in the dialog.
        '*************************************************************
        Case 2
            On Error Resume Next
            With cdlg
                .Flags = cdlOFNFileMustExist
                .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
                .ShowOpen
            End With
            If Err <> cdlg.cdlCancel Then OpenFile cdlg.filename
        '*************************************************************
        ' Index 3 is the separator, so don't do anything.
        '*************************************************************
        'Case 3
        '*************************************************************
        ' File Exit - Terminate the application
        '*************************************************************
        Case 4
            Unload Me
    End Select
End Sub
When the File, New menu is clicked (Index = 1), the Dim frmNew As New frmChild line creates a new instance of your child form. However, this doesn't really create the new form. The form is actually created as soon as you access one if its properties or methods. This means that the frmNew.Visible = True line is the line of code that creates the form. After the form is created, the Visible property is set to True, which displays your form.
tip.gif
Forms created using New are hidden by default, so remember to display them by setting Visible = True.

 
< previous page page_403 next page >